package org.nerve.commons.util;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * org.nerve.selenium.util
 * Created by zengxm on 2016/4/19 0019.
 */
public final class UrlUtils {
	protected static final String HTTP="http://";

	public static String urlToFileName(String url){
		if(url==null)
			return "_";
		String u=url.toLowerCase().trim();
		if(u.startsWith(HTTP))
			u=u.replaceFirst(HTTP,"");
		try {
			u= URLEncoder.encode(u,"utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		if(u.length()>=100)
			u=u.substring(0,100);
		return u+".png";
	}
}
